@extends('admin.layouts.layout')
@section('content')
    <?php
    use \App\Models\Enum\MailStatus;
    use \App\Models\Enum\MailType;
    ?>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox-title">
                <h5>邮件审核</h5>
            </div>
            <div class="ibox-content">
                @include('widget.refresh')
                <form class="form-horizontal " action="{{route('mail.index')}}" method="post"
                      enctype="multipart/form-data">
                    {!! csrf_field() !!}
                    <input type="hidden" name="page_size" value="{{old('page_size')}}"/>
                </form>
                <table class="table table-striped table-bordered table-hover m-t-md tblData">
                    <thead>
                    <tr>
                        {{--                        <th class="text-center">全选</th>--}}
                        <th class="text-center">ID</th>
                        <th class="text-center">渠道</th>
                        <th class="text-center">服务器</th>
                        <th style="width: 10%" class="text-center">标题</th>
                        <th style="width: 15%" class="text-center">内容</th>
                        <th style="width: 15%" class="text-center">发放理由</th>
                        <th class="text-center">附件</th>
                        <th class="text-center">邮件类型</th>
                        <th class="text-center">目标玩家</th>
                        <th class="text-center">管理员</th>
                        <th class="text-center">编辑时间</th>
                        <th class="text-center">状态</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody class="text-center" id="tbContainer">
                    @foreach($mails as $key => $item)
                        <tr data-id="{{$item['id']}}">
                            {{--                            <td></td>--}}
                            <td>{{$item['id']}}</td>
                            <td>{{$item->channel->channel_name}}</td>
                            <td><?php echo isset($item->server->server_name) ? $item->server->server_name : ''?></td>
                            <td>{{$item['title']}}</td>
                            <td>{{str_replace('%5Cn', "\\n", $item['content'])}}</td>
                            <td>{{$item['reason']}}</td>
                            <td>
                                <?php
                                if ($item->mail_type == MailType::BATCH) {
                                    echo "<a href='{$item['attachment']}' target='_blank'>下载附件</a>";
                                } else {
                                    echo $item['attachment'];
                                }
                                ?>
                            </td>
                            <td>{{\App\Models\Enum\MailType::get($item['mail_type'])}}</td>
                            <td>{{$item['nickname']}}</td>
                            <td><?php if (isset($item->approver->name)) echo $item->approver->name;?></td>
                            <td>{{$item['updated_at']}}</td>
                            <td>
                                <?php
                                switch ($item['status']) {
                                    case MailStatus::UNCHECK:
                                        echo '<span class="label label-primary">' . MailStatus::get(MailStatus::UNCHECK) . '</span>';
                                        break;
                                    case MailStatus::CHECKING:
                                        echo '<span class="label label-info">' . MailStatus::get(MailStatus::CHECKING) . '</span>';
                                        break;
                                    case MailStatus::AGREE:
                                        echo '<span class="label label-success">' . MailStatus::get(MailStatus::AGREE) . '</span>';
                                        break;
                                    case MailStatus::BAN:
                                        echo '<span class="label label-danger">' . MailStatus::get(MailStatus::BAN) . '</span>';
                                        break;
                                    case MailStatus::CANCEL:
                                        echo '<span class="label label-warning">' . MailStatus::get(MailStatus::CANCEL) . '</span>';
                                        break;
                                    default:
                                        echo '未定义状态';
                                }
                                ?>
                            </td>
                            <td>
                                <?php
                                if ($item['status'] == MailStatus::CHECKING) {
                                    $agreeHref = route('mail.checkStatus', ['status' => MailStatus::AGREE, 'id' => $item->id]);
                                    $banHref = route('mail.checkStatus', ['status' => MailStatus::BAN, 'id' => $item->id]);
                                    echo <<< EOF
                                <a href="$agreeHref"><button type="button" class="btn btn-xs btn-info">同意</button></a>
                                <a href="$banHref"><button type="button" class="btn btn-xs btn-warning">拒绝</button></a>
EOF;
                                }
                                ?>
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
                <div class="pull-left pagination m-t-no">
                    @include('widget.page',['reqPageSize'=>$reqPageSize])
                </div>
                <div class="pull-right pagination m-t-no">
                    <div class="text-center">
                        <?php
                        if (count($mails) > 0) {
                            echo $mails->appends(['page_size' => app('request')->input('page_size')])->links();
                        }
                        ?>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <script>
    </script>
    <link href="{{loadEdition('/admin/css/plugins/datapicker/bootstrap-datepicker.css')}}" rel="stylesheet">
    <link href="{{loadEdition('/admin/js/plugins/bootstrap-table/bootstrap-table.min.css')}}" rel="stylesheet">
    <link href="{{loadEdition('/js/plugins/chosen_v1.8.7/chosen.min.css')}}" rel="stylesheet">

@endsection
@section('js')
    <!--bootstrap-datepicker start-->
    <script src="{{loadEdition('/admin/js/plugins/datapicker/bootstrap-datepicker.js')}}"></script>
    <script src="{{loadEdition('/admin/js/plugins/datapicker/bootstrap-datepicker.zh-CN.js')}}"></script>
    <!--bootstrap-datepicker end-->
    <!--bootstrap-table start-->
    <script src="{{loadEdition('/admin/js/plugins/bootstrap-table/bootstrap-table.min.js')}}"></script>
    <script src="{{loadEdition('/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js')}}"></script>
    <!--bootstrap-table end-->
    <!--chosen-->
    <script src="{{loadEdition('/js/plugins/chosen_v1.8.7/chosen.jquery.min.js')}}"></script>
    <script src="{{loadEdition('/js/plugins/chosen_v1.8.7/chosen.proto.min.js')}}"></script>
    <script src="{{loadEdition('/js/global.js')}}"></script>
    <script>
        $(document).ready(function () {

        });
    </script>
@stop